package com.example.huangyuchen.advance.training.camp.composition.modifier;

import com.example.huangyuchen.advance.training.camp.composition.Composition;
import com.example.huangyuchen.advance.training.camp.composition.NeedCompositionClass;
import lombok.AllArgsConstructor;

import java.nio.charset.StandardCharsets;

/**
 * @author YuChen Huang
 * @date 2022/3/5 18:50
 */
@AllArgsConstructor
public abstract class CompositionClassQtyModifier3 {

    private static NormalModifier NORMAL_INSTANCE;
    private static OtherModifier OTHER_INSTANCE;

    protected final String filed1;
    protected final String filed2;

    public synchronized static NormalModifier getNormalModifier(String filed1, String filed2) {
        if (NORMAL_INSTANCE == null) {
            NORMAL_INSTANCE = new NormalModifier(filed1, filed2);
        }
        return NORMAL_INSTANCE;
    }

    public synchronized static OtherModifier getOtherModifier(String filed1, String filed2) {
        if (OTHER_INSTANCE == null) {
            OTHER_INSTANCE = new OtherModifier(filed1, filed2);
        }
        return OTHER_INSTANCE;
    }

    /**
     * @implNote 1
     * @param needCompositionClass 33
     */
    private void test(NeedCompositionClass needCompositionClass) {
//        needCompositionClass.qty = 1;
    }


    static class NormalModifier extends CompositionClassQtyModifier3 {

        private NormalModifier(String filed1, String filed2) {
            super(filed1, filed2);
        }

        public int i;

        public void modifyQtyForSon(Composition son) {
//            son.qty2 = 2;
            super.test(son);

            System.out.println("son = " + son);
        }
    }

    static class OtherModifier extends CompositionClassQtyModifier3 {

        private OtherModifier(String filed1, String filed2) {
            super(filed1, filed2);
        }


        public int i;

        public void modifyQtyForSon(Composition son) {
//            son.qty2 = 2;
            super.test(son);

            filed1.getBytes(StandardCharsets.UTF_8);
            filed2.getBytes(StandardCharsets.UTF_8);

            System.out.println("son = " + son);
        }
    }
}
